<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="mycss/redBtn.css" />
<script type="text/javascript" src="myjs/md5.js"></script>
<script lang=javascript>
<?php require("check_login.php"); ?>
<?php require("user_settings.php"); ?>
function chkPass()
{
	var p0=document.getElementById("oldpasswd");
	var p1=document.getElementById("passwd");
	var p2=document.getElementById("passwdConfirm");
	if((p1.value.length == 0) || (p2.value.length == 0))
		return false;
	if(p1.value != p2.value) {
		alert('密碼不一致');
		p2.value="";
		return false;
	}
	var hash = hex_md5(p1.value);
	p1.value = hash;
	p0.value = hex_md5(p0.value);
	//alert(document.getElementById("passwd").value);
	
}
</script>
<style>
label, textarea{
  display:inline-block;
  vertical-align:middle;

}
form {
	margin: 1em 0 0 1.5em;
}
label {
	float: left;
	width: 100px;
	margin-left: 1em;
}
p {
	clear: both;
}
fieldset {
margin: 1.5em 0em 0em 1.5em;
padding: 0;
border: 1px solid #CCC;
width: 600px;
}
legend {
margin-left: 1em;
color: #009;
font-weight: bold;
}
</style>
<style> 
.myinput{
	border: #C0C0C0 1px solid;
	border-radius: 5px;
	/** remember to change image path **/
	background: url(none) no-repeat #ffffff;
	font-family: tahoma, helvetica, sans-serif;
	font-style: normal;
	font-size: 14px;
	color: #454743;
}

 </style> 
<style type="text/css">
body{
    font-family: Cambria, Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, serif;
    background: #fff url(images/bg.jpg) repeat top left;
    font-weight: 400;
    font-size: 15px;
    color: #1d3c41;
    overflow-y: scroll;
}
</style>
<?php
	if(isset($_GET['oldpasswd'])) {
		$uid=$_SESSION['id'];
		#$user_file = "passwd.json";
		#$users = json_decode(file_get_contents($user_file),true);
		$ret = verifyUser($uid, htmlspecialchars($_GET['oldpasswd']));
		#if(!isset($users[$uid])) {
		if($ret == "ERR_USER_NONEXIST") {
			echo "<H1> $uid User not Exist </H1>";
			die("USER NOT FOUND");
		}
		#if($users[$uid] == $_GET['oldpasswd']) {
		if($ret == "OK_OK") {#$users[$uid] == $_GET['oldpasswd']) {
			#$users = getUser($uid);
			#$users[$uid] = $_GET['passwd'];
			#file_put_contents("$user_file",json_encode($users));
			modUser($uid, htmlspecialchars($_GET['passwd']));
			echo "<font color='red'>密碼更新成功</font>";
		}
		else {
			echo "<font color='red'>舊密碼驗証錯誤</font>";
		}
	}



?>
<?php
	#if(file_exists("users/".$uid."/pic.jpg")) {
	#	echo "<img src=users/".$uid."/pic.jpg width=160 height=120>";
	#} 
	#else
	#	echo "Photo not update<BR>";
?>
<!--
<form id="uploadform" action="upload_pic.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
-->

<form name="settings" action="myinfo.php">
	<input type=hidden name=savePref value=yes>
	<input type=hidden name=uid value=$uid>
<?php
	#echo "<input type=hidden name=uid value=$uid>";
	echo "舊密碼: <Input type=password name=oldpasswd id=oldpasswd class='myinput'><BR>";
	echo "新密碼: <Input type=password name=passwd id=passwd class='myinput'><BR>";
	echo "重輸入: <Input type=password name=passwdConfirm id=passwdConfirm class='myinput'><BR>";
	#echo "Accent: <Input type=text name=accent value=\"".$users['accent']."\"><BR>";
	#echo "Age: <Input type=text name=age value=\"".$users['age']."\"><BR>";
	#echo "Job: <Input type=text name=job value=\"".$users['job']."\"><BR>";
	#echo "Identity: <Input type=text name=identity value=\"".$users['identity']."\"><BR>";
	#echo "Expertise: <Input type=text name=expertise value=\"".$users['expertise']."\"><BR>";
	#//echo "Brief: <Input type=text name=brief value=\"".$users['brief']."\"><BR>";
	#echo "Brief: <textarea name=\"brief\" rows=5 cols=80>";
	#echo $users['brief'];
	#echo "</textarea>";
?>
	<BR>
	<input type=submit value="儲存" class='redBtn' onclick='chkPass()'>
</form>
